1334D - Minimum Euler Cycle - CodeForces Solution


constructive algorithms graphs greedy implementation *1800

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fori(n)         for (ll i=0; i<n; i++) 
#define forj(n)         for (ll j=0; j<n; j++) 
#define fork(n)         for (ll k=0; k<n; k++) 
#define Sort(a)         sort(a.begin(),a.end())
#define pd pair<ll, ll>
#define YES  cout<<"YES"<<endl
#define NO   cout<<"NO"<<endl

using namespace std;

// ncr 

/*  void prllNcR(ll n, ll r)
{
 
    // p holds the value of n*(n-1)*(n-2)...,
    // k holds the value of r*(r-1)...
    long long p = 1, k = 1;
 
    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;
 
    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;
 
            // gcd of p, k
            long long m = __gcd(p, k);
 
            // dividing by gcd, to simplify
            // product division by their gcd
            // saves from the overflow
            p /= m;
            k /= m;
 
            n--;
            r--;
        }
 
        // k should be simplified to 1
        // as C(n, r) is a natural number
        // (denominator should be 1 ) .
    }
 
    else
        p = 1;
 
    // if our approach is correct p = ans and k =1
    cout << p << endl;
}  */







//nCr%p
/*      unsigned long long power(unsigned long long x, 
                                  ll y, ll p)
{
    unsigned long long res = 1; // Initialize result
  
    x = x % p; // Update x if it is more than or
    // equal to p
  
    while (y > 0) 
    {
      
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;
  
        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
  
// Returns n^(-1) mod p
unsigned long long modInverse(unsigned long long n,  
                                            ll p)
{
    return power(n, p - 2, p);
} 
  
// Returns nCr % p using Fermat's little
// theorem.
 unsigned long long nCrModPFermat(unsigned long long n,
                                 ll r, ll p)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;
  
    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    unsigned long long fac[n + 1];
    fac[0] = 1;
    for (ll i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;
  
    return (fac[n] * modInverse(fac[r], p) % p
            * modInverse(fac[n - r], p) % p)
           % p;
}     */





//ll M=998244353; 
// GRAPH



// SIEVE 
/*      const ll N = 10002;
vector<ll> lp(N+1);
vector<ll> pr;

void Sieve()
{
for (ll i=2; i <= N; ++i) {
    if (lp[i] == 0) {
        lp[i] = i;
        pr.push_back(i);
    }
    for (ll j = 0; i * pr[j] <= N; ++j) {
        lp[i * pr[j]] = pr[j];
        if (pr[j] == lp[i]) {
            break;
        }
    }
} 
}      */



// BINPOW
 ll power(ll x, ll y, ll p)
{
    ll res = 1;     // Initialize result
 
    x = x % p; // Update x if it is more than or
                // equal to p
  
    if (x == 0) return 0; // In case x is divisible by p;
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
} 
/*  vector<long long> trial_division2(long long n) {
    vector<long long> factorization;
    while (n % 2 == 0) {
        factorization.push_back(2);
        n /= 2;
    }
    for (long long d = 3; d * d <= n; d += 2) {
        while (n % d == 0) {
            factorization.push_back(d);
            n /= d;
        }
    }
    if (n > 1)
        factorization.push_back(n);
    return factorization;
}  */

/* ll MODFact(ll n, ll p)
{
    if (n >= p)
        return 0;
 
    ll result = 1;
    for (ll i = 1; i <= n; i++)
        result = (result * i) % p;
 
    return result;
}
ll MOD=998244353; */

ll MOD=998244353;


int main()
{
    ios::sync_with_stdio(false);
	cin.tie(nullptr); 
    ll t,i;
    t=1;
    cin>>t; 
    fori(t)
    {
        ll n,l,r;
        cin>>n>>l>>r;
        vector<ll>v;
        v.push_back(0);
        ll sum=0;
        forj(n)
        {
            if((n-1-j)>0)
            {
                sum=sum+2*(n-1-j);
                v.push_back(sum);
            }
            
        }
        auto it=lower_bound(v.begin(),v.end(),l);
        
        it--;
        ll dis=distance(v.begin(),it);
        ll ix=*(it);
        ll ct=r-l+1;
        ll alpha=dis+1;
        ll beta=alpha+1;
        ix=ix+1;
        ll ar=n*(n-1)+1;
        while(ix<=r)
        {
            if(ix==ar)
            {
            cout<<1;
            break;
            }
            else
            {
            if(ix>=l)
            {
                if(ix%2==1)
                {
                    cout<<alpha<<" ";

                }
                else
                {
                    cout<<beta<<" ";
                }
                
            }
            if(ix%2==0 && beta==n)
            {
                alpha++;
                beta=alpha+1;
                ix++;
            }
            else if(ix%2==0)
            {
                ix++;
                beta++;
            }
            else
            ix++;
            }

        }
        cout<<endl;
            
    }

}


Comments

Submit
0 Comments
More Questions

1337B - Kana and Dragon Quest game
137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble
6A - Triangle
1729A - Two Elevators
1729B - Decode String
1729C - Jumping on Tiles
1729E - Guess the Cycle Size
553B - Kyoya and Permutation
1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park
342A - Xenia and Divisors
1033A - King Escape
39D - Cubical Planet
1453A - Cancel the Trains
645A - Amity Assessment
1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring
630N - Forecast
312B - Archer
34D - Road Map
630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya